package top.lyunz.fangkeji.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class webConfigurer implements WebMvcConfigurer {
	// 这个方法是用来配置静态资源的，比如html，js，css，等等
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		registry.addResourceHandler("/img/**").addResourceLocations("file:C:\\img\\");
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}

	// 这个方法用来注册拦截器，我们自己写好的拦截器需要通过这里添加注册才能生效
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// addPathPatterns("/**") 表示拦截所有的请求，
		// excludePathPatterns("/login", "/register") 表示除了登陆与注册之外，因为登陆注册不需要登陆也可以访问
		registry.addInterceptor(new Interceptor()).addPathPatterns("/web/**", "/redirect/**"
				
				//, "/wechat/**"
				)
				.excludePathPatterns("/redirect/tologin", "/redirect/toregisteruser", "/redirect/toupdpwd",
						"/web/userregister", "/web/verificationCode/**", "/web/updpwdverificationCode/**",
						"/web/dologin", "/web/doupdpwd", "/wechat/doupdpwd", "/static/**", "/web/dologinToChoose"
//						,"/wechat/invitationAndAppointmentGetCode/**"
//						, "/wechat/doAddAppointmentMember",
//						"/wechat/toAddAppointmentMember/**", "/wechat/initiateAppointment/**",
//						"/wechat/getByusertel/**", "/wechat/getallAppointmentRecord/**", "/wechat/selfHelpRegistration",
//						"/wechat/userregister", "/wechat/verificationCode/**", "/wechat/updpwdverificationCode/**",
//						"/wechat/dologin","/wechat/dologinToChoose","/wechat/doupdpwd","/redirect/sessionisnull"
						
						);
		WebMvcConfigurer.super.addInterceptors(registry);
	}

	// 设置默认页面
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/").setViewName("forward:/redirect/tologin");
		// 设置优先级 当请求地址有重复的时候 执行优先级最高的
		registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
		WebMvcConfigurer.super.addViewControllers(registry);

	}
}
